<template>
	<view>

		<view class="content_item" v-for="(item,index) in activityinfo" :key="index">

			<!-- ======================================== -->

			<view class="cu-card article" :class="isCard?'no-card':''">
				<view class="cu-item shadow">
					<view class="title">
						<view class="text-cut">{{item.activityname}}</view>
					</view>
					<view class="content">
						<!-- <image src='../../static/ganjiang.png' -->
						<image :src="item.imagePath[0]" mode="aspectFill"></image>
						<view class="desc">
							<view class=".topic_cont_text text-gray" style="margin: 10rpx;">
								{{item.detailCout}}
							</view>

							<!-- <view>
								<view class="cu-tag bg-red light sm round">王者荣耀</view>
								<view class="cu-tag bg-green light sm round">苏烈</view>
								
							</view> -->
							<!-- 这里要加一个按钮 -->
							<view class="flex-wrap" style="margin-left: 30rpx;">
								<button @click="startSign(item.activityname)" class="cu-btn round bg-gradual-orange">开始签到</button>
								<button style="margin-left: 10rpx;" @click="manageActByName(item.activityname)" class="cu-btn round bg-gradual-pink">管理活动</button>
							</view>
							
						</view>
					</view>
				</view>
			</view>



		</view>
		<!-- ======================================== -->
		<down-block></down-block>
	</view>
	</view>
</template>

<script>
	import customTarbar from '@/wxcomponents/custom-tarbar/custom-tarbar.vue';
	import cuCustom from '../../colorui/components/cu-custom.vue'
	import downBlock from '../../components/down_block.vue'
	export default {
		components: {
			'custom-tarbar': customTarbar,
			cuCustom,
			downBlock
		},
		data() {
			return {
				isCard: false,
				activityinfo: [],
				
			}
		},
		methods: {
			manageActByName(activityName){
				uni.navigateTo({
					url:'../manageActivityUser/manageActivityUser?activityname='+activityName
				})
			},
			async getDetail(){
				let username=JSON.parse(uni.getStorageSync("USERS_KEY")).username
				const baseurl=getApp().globalData.BASE_URL
				const res = await this.$myRequest({
					url:'/Manage/activity',
					data:{
						userName:username
					},
					
					
				})
				console.log(res)
				this.activityinfo=res.data;
				// 对图片的url进行遍历修改
				for(let j=0;j<this.activityinfo.length;j++){	
					for(let i=0;i<this.activityinfo[j].imagePath.length;i++){
						if(this.activityinfo[j].imagePath[i].indexOf("http")==-1){
							// 如果图片url里面没有http字体那边加上baseurl
 							this.activityinfo[j].imagePath[i]=baseurl+this.activityinfo[j].imagePath[i];
						}
					}
				}
				console.log("修改后的url",this.activityinfo)
			},
			async startSign(title){
				const baseurl=getApp().globalData.BASE_URL
				uni.request({
					url:baseurl+"/sign/startSign/",
					data:{
						title:title
					},
					success(res) {
						if(res.statusCode==200)
						{
							uni.showToast({
								icon:'none',
								title:"开始签到\n签到码："+res.data,
								duration:6000,
							})
						}else{
							uni.showToast({
								icon:'none',
								title:"签到已开始\n签到码："+res.data,
								duration:6000,
							})
						}
					},
					fail(res) {
						console.log("fail",res)
						uni.showToast({
							title:"签到已开始",
							duration:2000,
							success() {
								uni.showToast({
									icon:'none',
									title:"签到码："+res.data,
									duration:5000,
								})
							}
						})
					}
					
				})
				
			}
		},
		onLoad() {
			this.getDetail()
		},
		onShow() {
			//获取数据
			console.log(this.activityinfo)
		}
	}
</script>

<style>

</style>
